package com.csd.controller;

import com.csd.dto.ActionResult;
import com.csd.mapper.SysAdminMapper;
import com.csd.po.SysUser;
import com.csd.service.SysAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @program: CeSuDi_SSM
 * @description: 管理员管理业务表现层
 * @author: xiaojiu
 * @create: 2020-12-23 16:58
 */
@Controller
public class UserInfoController {
   @Autowired
    private SysAdminService sysAdminService;

    /**
     * 显示会员列表
     * @return
     */
    @RequestMapping(value = "/getSysUser",method = RequestMethod.POST)
   @ResponseBody
    public List<SysUser> getSysUser(){
        List<SysUser> sysUsers = sysAdminService.findUsers();

    return sysUsers;
    }

    /**
     * 删除会员成员
     * @param id
     * @return
     */
    @RequestMapping(value = "/delSysUser",method = RequestMethod.DELETE)
    @ResponseBody
    public ActionResult  delSysUser(int id){
        System.out.println(id);
     sysAdminService.deleteSysUserById(id);

    return new ActionResult(200,"会员删除成功",null);
    }

    /**
     * 在模态框根据id显示成员
     * @param id
     * @return
     */

    @RequestMapping(value = "/getUserInfoById",method = RequestMethod.GET)
    @ResponseBody
    public ActionResult getUserInfoById(int id){
        SysUser user = sysAdminService.findUserById(id);

        return new ActionResult(200,null,user);
    }

    @RequestMapping(value = "/modify",method = RequestMethod.PUT)
    @ResponseBody
    public ActionResult modify(@RequestBody SysUser sysUser){
        sysAdminService.updateUser(sysUser);
        System.out.println(sysUser);
        return new ActionResult(200,"信息修改成功",null);
    }
}
